<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible="dialogVisible"
    title="出库管理"
    width="80%"
    :before-close="handleClose"
  >
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form
          label-width="49px"
          :inline="true"
          :model="queryForm"
          @submit.native.prevent
        >
          <el-form-item label="类型">
            <el-select v-model="queryForm.Type" placeholder="请选择">
              <el-option
                v-for="item in Types"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="直径">
            <el-select v-model="queryForm.Diameter" placeholder="请选择">
              <el-option
                v-for="item in Diameters"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="R角">
            <el-select v-model="queryForm.Rangle" placeholder="请选择">
              <el-option
                v-for="item in Rangles"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="刃长">
            <el-select v-model="queryForm.BladeLengt" placeholder="请选择">
              <el-option
                v-for="item in BladeLengths"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="材质">
            <el-select v-model="queryForm.Material" placeholder="请选择">
              <el-option
                v-for="item in Materials"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-table
      ref="tableSortRef"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column
        v-for="(item, index) in finallyColumns"
        :key="index"
        align="center"
        :label="item.label"
        :prop="item.prop"
        :sortable="item.sortable"
        width="auto"
      >
        <template slot-scope="scope">
          <span>{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <template slot="empty">
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <template slot="footer">
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <template>
          <el-button type="primary" @click="submit">出口</el-button>
        </template>
      </span>
    </template>
  </el-dialog>
</template>

<script>
  import {
    KnifeInfoThresholdList,
    SerachItemList,
    KnifeLibOut,
  } from '@/api/material'
  export default {
    props: {
      columns: {
        type: Array,
        default: () => {
          return []
        },
      },
      checkList: {
        type: Array,
        default: () => {
          return []
        },
      },
    },
    data() {
      return {
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
        },

        Types: [],
        BladeLengths: [],
        Diameters: [],
        Rangles: [],
        Materials: [],
        list: [],
        total: 0,
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
        },

        layout: 'total, sizes, prev, pager, next, jumper',
        dialogVisible: false,

        multipleSelection: [],
      }
    },
    computed: {
      finallyColumns() {
        return this.columns.filter((item) =>
          this.checkList.includes(item.label)
        )
      },
    },
    mounted() {
      this.fetchData()
    },
    methods: {
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      submit() {
        if (this.multipleSelection.length == 0) {
          this.$baseMessage('请选择', 'error', 'vab-hey-message-success')
          return false
        }
        KnifeLibOut(this.multipleSelection.map((v) => v.Id)).then((res) => {
          this.$baseMessage('成功', 'success', 'vab-hey-message-success')
          this.dialogVisible = false
          this.multipleSelection = []
        })
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      show() {
        console.log('aaaaaaaaaaaaaaaaaaa')
        this.dialogVisible = true
        this.query()
        this.fetchData()
      },
      handleClose() {
        this.dialogVisible = false
      },
      query() {
        SerachItemList().then((res) => {
          this.Types = res.Types.filter((v) => v)
          this.BladeLengths = res.BladeLengths.filter((v) => v)
          this.Diameters = res.Diameters.filter((v) => v)
          this.Rangles = res.Rangles.filter((v) => v)
          this.Materials = res.Materials.filter((v) => v)
        })
      },
      queryData() {
        this.fetchData()
      },
      fetchData() {
        const params = {
          Index: this.getPage(this.queryForm.pageNo, this.queryForm.pageSize),
          Count: this.queryForm.pageSize,
          Type: this.queryForm.Type,
          Diameter: this.queryForm.Diameter,
          Rangle: this.queryForm.Rangle,
          BladeLength: this.queryForm.BladeLength,
          Material: this.queryForm.Material,
        }
        KnifeInfoThresholdList(params).then((res) => {
          console.log(res)
          this.list = res.KnifeInfo
          this.total = res.TotalCount
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
